<?
// Database Connection
$dbname = 'tcntransition';
$dbhost = 'cougar.wou.edu';
$dbuser = 'tcntransition';
$dbpass = 'transit';
$db = mysql_connect($dbhost,$dbuser,$dbpass);

function getResources($levelID=null,$level=null) {
	global $resourceString, $dbname, $db, $db_selected;
	$resourceString = '';
	
	// Get path from levelID
	$sql  = "SELECT Path from transLevels WHERE LevelID = '$levelID'";
	$result = mysql_db_query($dbname,$sql);
	$row = mysql_fetch_assoc($result);
	
	$path   = $row[Path];
	$pathID = $levelID;
	
	// Parse path and get path title
	$breadCrumbs = buildBreadcrumbs($path);
	
	// Get resources
	$sql = "SELECT * from transLinks TL
				LEFT JOIN transLinkPath LP ON TL.LinkID = LP.LinkID
				WHERE LP.PathID = '$pathID'
				ORDER BY TL.DateCreated DESC";
	$result = mysql_db_query($dbname,$sql);
	$rows = mysql_num_rows($result);
	if ($rows<1) {
		$resourceString .= 'There are no links in this category yet.';
	} else {		
		$i=1;
		while ($value = mysql_fetch_assoc($result)) {
			if (($i % 2) > 0) { $class = 'noRowClass'; }
			else { $class = "altRow"; }
			$linkID     = $value[LinkID];
			$linkTitle  = stripslashes($value[Title]);
			$linkDesc   = stripslashes($value[LinkDescription]);
			$linkDate   = $value[DateCreated];
			$linkURL    = $value[Link];
			$linkStatus = $value[Status];
			$linkViews  = $value[Views];
			$linkRankTotal = $value[RankTotal];
			$linkRanks  = $value[Ranks];
			$linkErrorCode  = $value[ErrorCode];
			$linkErrorLevel = $value[ErrorLevel];  
			$addUserID      = $value[UserID];
			
			// Get contributor name
			$sql2 = "SELECT FullName from transLogin WHERE UID = '$addUserID'";
			$result2 = mysql_db_query($dbname,$sql2);
			$rows = mysql_fetch_assoc($result2);
			$contributorName = $rows[FullName];
			if (empty($contributorName)) {
				$contributorName = 'Anonymous';
			}
			
			$contentArray = array(
									$class,
									$linkID,
									$linkTitle,
									$linkURL,
									$linkDesc,
									$linkDate,
									$linkViews,
									$contributorName,
									$linkStatus
								);
			$resourceString .= renderResources($contentArray);
			$i++;
		}
		
	} 
	$resourceString = $breadCrumbs.'|'.$resourceString.'|'.$levelID;
	return $resourceString;
}

function getNewResources() {
	global $newResourceString, $dbname, $db, $db_selected;
	$resourceString = '';
	
	$sql = "SELECT * from transLinks WHERE Status = '0' ORDER BY DateCreated DESC";
	$result = mysql_db_query($dbname,$sql);
	$rows = mysql_num_rows($result);
	if ($rows<1) {
		$resourceString .= 'No new links have been added at this time.';
	} else {
		
		$i=1;
		while ($value = mysql_fetch_assoc($result)) {
			if (($i % 2) > 0) { $class = 'noRowClass'; }
			else { $class = "altRow"; }
			$linkID     = $value[LinkID];
			$linkTitle  = stripslashes($value[Title]);
			$linkDesc   = stripslashes($value[LinkDescription]);
			$linkDate   = $value[DateCreated];
			$linkURL    = $value[Link];
			$linkStatus = $value[Status];
			$linkViews  = $value[Views];
			$linkRankTotal = $value[RankTotal];
			$linkRanks  = $value[Ranks];
			$linkErrorCode  = $value[ErrorCode];
			$linkErrorLevel = $value[ErrorLevel];  
			$addUserID      = $value[UserID];
						
			// Get contributor name
			$sql2 = "SELECT FullName from transLogin WHERE UID = '$addUserID'";
			$result2 = mysql_db_query($dbname,$sql2);
			$rows = mysql_fetch_assoc($result2);
			$contributorName = $rows[FullName];
			if (empty($contributorName)) {
					$contributorName = 'Anonymous';			}
			$contentArray = array(									$class,									$linkID,									$linkTitle,									$linkURL,									$linkDesc,									$linkDate,									$linkViews,									$contributorName,									$linkStatus								);			$resourceString .= renderResources($contentArray);
			$i++;
		}
	} // End ELSE
	$newResourceString = 'New Link Submissions|'.$resourceString.'|0';
	return $newResourceString;
}

function linkCheck() {
	global $checkString, $dbname, $db, $db_selected;
	
	// Get last run date
	$sql = "SELECT * from transLinkCheckDate LIMIT 1";
	$result = mysql_db_query($dbname,$sql);
	$row = mysql_fetch_assoc($result);
	$runDate = mysql_to_date2($row[RunDate]);
	$runBy   = $row[Userid];
	
	// Get number of links to check
	$sql = "SELECT COUNT(*) from transLinks WHERE ErrorLevel = '0'";
	$result = mysql_db_query($dbname,$sql);
	$row = mysql_fetch_row($result);
	$noLinks = $row[0];
	
	$checkString = $runDate.'|'.$runBy.'|'.$noLinks;
	return $checkString;
}

function linkCheckConfirm($start=null,$totalLinks=null) {
	global $linkCheckString, $html, $status, $dbname, $db, $db_selected;
	$badLinkString = '';
	if (empty($start)) { 
		$start = 0; 
		// Update last link check date
		$sql = "UPDATE transLinkCheckDate SET RunDate = '".date('Y-m-d')."'";
		$result = mysql_db_query($dbname,$sql);
	}
	
	$sql = "SELECT LinkID,Link from transLinks WHERE ErrorLevel = '0' ORDER BY Title LIMIT $start,1";
	$result = mysql_db_query($dbname,$sql);
	while ($value = mysql_fetch_assoc($result)) {
		// Call link check function
		$linkID = $value[LinkID]; 
		$url    = $value[Link];
		linkChecker($url);
		if ($html) { getstatuscode($html); }
		
		// Parse status
		$statusCode = substr($status,0,4);
		if ( ($statusCode == 400) || ($statusCode == 404) || ($statusCode == 301) || ($statusCode == 408) ) {
			$siteError = 1;
		} else {
			$siteError = 0;
		}
		//$badLinkString .= $status.' siteError: '.$siteError.' statusCode'.$statusCode.'<br>';
		
		// Update transLinks
		$sql2 = "UPDATE transLinks SET 
				ErrorCode = '$statusCode', 
				ErrorLevel = '$siteError' 
				WHERE LinkID = '$linkID'";
		$result2 = mysql_db_query($dbname,$sql2);
	}
	
	// Now get all links that have siteError = 1 so we can display them
	$sql = "SELECT LinkID,Title,Link from transLinks WHERE ErrorLevel = '1' ORDER BY Title";
	$result = mysql_db_query($dbname,$sql);
	$rows = mysql_num_rows($result);
	if ($rows>0) {
		
		while ($value = mysql_fetch_assoc($result)) {
			$linkID    = $value[LinkID];
			$linkTitle = $value[Title];
			$linkURL   = $value[Link]; 
			$badLinkString .= '<a href="#" onClick="linkDelete('.$linkID.'); return false;"><img src="images/button_delete.gif" style="border: none;" alt="Delete Link"></a> <a href="'.$linkURL.'" target="_blank">'.$linkTitle.'</a><br />';
		}
	}
	
	$start = $start+1;
	$percentComplete = ceil( ($start/$totalLinks)*100 );
	$decComplete = number_format(($start/$totalLinks),2);
	$barSize         = ceil(300*$decComplete);
	$linkCheckString = $start.'|'.$totalLinks.'|'.$percentComplete.'|'.$barSize.'|'.$badLinkString;
	
	return $linkCheckString;
}

function getLevelSelects($levelPath=null,$levelNumber=null,$parentNode=null) {
	global $levelString, $dbname, $db, $db_selected;
	$level1String = '';
	$level2String = '';
	$level3String = '';
	
	if (empty($parentNode)) { $parentNode = 'pathSelect1'; }
	
	// $levelPath is in the form of /mainCat/subCat/subSubCat	
	if (!empty($levelPath)) {
		$pathArray = explode('/',$levelPath);
		$mainCat   = $pathArray[1];
		$subCat    = $pathArray[2];
		$subSubCat = $pathArray[3];
		$status = $mainCat;
		
		if (!empty($mainCat)) {		
			$sql = "SELECT * from transLevels WHERE Path = '/$mainCat'";
			$result = mysql_db_query($dbname,$sql);
			$row = mysql_fetch_assoc($result);
			$mainCatName = stripslashes($row[LevelName]);
			$levelNumber = 1;
		}
		if (!empty($subCat)) {		
			$sql = "SELECT * from transLevels WHERE Path = '/$mainCat/$subCat'";
			$result = mysql_db_query($dbname,$sql);
			$row = mysql_fetch_assoc($result);
			$subCatName = stripslashes($row[LevelName]);
			$levelNumber = 2;
		}
		if (!empty($subSubCat)) {		
			$sql = "SELECT * from transLevels WHERE Path = '/$mainCat/$subCat/$subSubCat'";
			$result = mysql_db_query($dbname,$sql);
			$row = mysql_fetch_assoc($result);
			$subSubCatName = stripslashes($row[LevelName]);
			$levelNumber = 3;
		}		
	}	
	// Now get all main,sub,subSub cats for select menus
	// This is dependent upon the levelNumber
	// Only display mainCat and subCat selectMenu
	$level1String .= '<select id="mainCat" size="1" style="width: 200px;" onChange="getLevel(this.options[this.selectedIndex].value,1,this.parentNode.id); return false;">';
	$sql = "SELECT * from transLevels WHERE MainCat = '1' AND InMainMenu = '1' ORDER BY LevelName";
	$result = mysql_db_query($dbname,$sql);
	
	$level1String .= '<option>Select...</option>';
	while ($value = mysql_fetch_assoc($result)) {
		$levelID   = $value[LevelID];
		$levelName = stripslashes($value[LevelName]);
		$levelPath = $value[Path]; 
		$level1String .= '<option value="'.$levelPath.'"';
		if ($levelPath == '/'.$mainCat) { $level1String .= ' selected '; }	
		$level1String .= '>'.$levelName.'</option>';	
	}			
	$level1String .= '</select>';
	
	if ($levelNumber > 0) {
		// Render subCat select menu
		$level2String .= '<select id="subCat" size="1" style="width: 200px;" onChange="getLevel( (this.options[this.selectedIndex].value),2,this.parentNode.id); return false;">';
		$sql = "SELECT * from transLevels WHERE Path LIKE '%/$mainCat%' AND SubCat = '1' AND InMainMenu = '1' ORDER BY LevelName";
		$result = mysql_db_query($dbname,$sql);
		
		$level2String .= '<option>Select...</option>';
		while ($value = mysql_fetch_assoc($result)) {
			$levelID   = $value[LevelID];
			$levelName = stripslashes($value[LevelName]);
			$levelPath = $value[Path]; 
			$level2String .= '<option value="'.$levelPath.'"';
			if ($levelPath == '/'.$mainCat.'/'.$subCat) { $level2String .= ' selected '; }	
			$level2String .= '>'.$levelName.'</option>';	
		}			
		$level2String .= '</select>';
	}
	if ($levelNumber > 1) {
		// Render subSubCat select menu
		$nextPathNumber = $pathNumber+1;
		$level3String .= '<select id="subSubCat" size="1" style="width: 200px;">';
		
		$sql = "SELECT * from transLevels 

				WHERE 

				Path LIKE '%/$mainCat/$subCat%' AND

				Path <> '/$mainCat/$subCat'

				ORDER BY LevelName";
		$result = mysql_db_query($dbname,$sql);
		
		$level3String .= '<option>Select...</option>';
		while ($value = mysql_fetch_assoc($result)) {
			$levelID   = $value[LevelID];
			$levelName = stripslashes($value[LevelName]);
			$levelPath = $value[Path]; 
			$level3String .= '<option value="'.$levelPath.'"';
			if ($levelPath == '/'.$mainCat.'/'.$subCat.'/'.$subSubCat) { $level3String .= ' selected '; }	
			$level3String .= '>'.$levelName.'</option>';	
		}			
		$level3String .= '</select>';
	}
	
	$levelString = $level1String.'&nbsp;'.$level2String.'&nbsp;'.$level3String;
	$levelString .= '|'.$status.'|'.$levelNumber.'|'.$parentNode;
	return $levelString;
}

function saveResource($phpString,$action=null,$linkID=null) {
	global $returnString, $dbname, $db, $db_selected;

	$userid    = $_SESSION[UID];
	$userLevel = $_SESSION['userLevel'];
	if ($userLevel == 1) {
		$status = '1';
	} else {
		$status = '0';
	}
	
	// Parse string
	$varArray = explode('|',$phpString);	
	
	// Clean input
	$linkTitle = fieldToDB($varArray[0]);
	$linkURL   = fieldToDB($varArray[1]);
	$linkDesc  = $varArray[2];
	
	// Insert into database
	if ($action == 'add') {
		$sql = "INSERT into transLinks (
				Title,
				LinkDescription,
				Link,
				UserID,
				DateCreated,
				Status			
				) values (
				'$linkTitle',
				'$linkDesc',
				'$linkURL',
				'$userid',
				'".date('Y-m-d')."',
				'$status'
				)";
		$result = mysql_db_query($dbname,$sql);	
	
		// Get MAX(LinkID)
		$sql = "SELECT MAX(LinkID) from transLinks WHERE UserID = '$userid'";
		$result = mysql_db_query($dbname,$sql);
		$row = mysql_fetch_row($result);
		$linkID = $row[0];	

		$sql = "UPDATE transLinkPath SET LinkID = '$linkID' WHERE LinkID = '0' AND Userid = '$userid'";
		$result = mysql_db_query($dbname,$sql);
	} elseif ($action == 'edit') {
		$sql = "UPDATE transLinks SET
				Title           = '$linkTitle',
				LinkDescription = '$linkDesc',
				Link            = '$linkURL',
				ErrorCode       = '',
				ErrorLevel      = '0'
				WHERE LinkID = '$linkID'";
		$result = mysql_db_query($dbname,$sql);		
	}
	//$returnString = $sql;
	return $returnString;
}

function toggleLinkStatus($linkID=null,$status=null) {
	global $returnLinkID, $dbname, $db, $db_selected;
	
	if ($status == 1) { $newStatus = 0; }
	elseif ($status == 0) { $newStatus = 1; }
	
	$sql = "UPDATE transLinks SET Status = '$newStatus' WHERE LinkID = '$linkID'";
	$result = mysql_db_query($dbname,$sql);
	$returnLinkID = $linkID.'|'.$newStatus;
	return $returnLinkID;
}

function toggleLinkStatus2($linkID) {
	global $returnLinkID, $dbname, $db, $db_selected;
	
	$sql = "UPDATE transLinks SET Status = '1' WHERE LinkID = '$linkID'";
	$result = mysql_db_query($dbname,$sql);
	$returnLinkID = $linkID;
	return $returnLinkID;
}

function deleteResource($linkID) {
	global $returnLinkID, $dbname, $db, $db_selected;
	
	$sql = "DELETE from transLinks WHERE LinkID = '$linkID'";
	$result = mysql_db_query($dbname,$sql);
	$sql = "DELETE from transLinkPath WHERE LinkID = '$linkID'";

	$result = mysql_db_query($dbname,$sql);

	$returnLinkID = $linkID;
	return $returnLinkID;
}

function resourceEdit($linkID) {
	global $returnEditString, $levelString, $dbname, $db, $db_selected;
	
	// Retrieve link details
	$sql = "SELECT * from transLinks WHERE LinkID = '$linkID'";
	$result = mysql_db_query($dbname,$sql);
	$row = mysql_fetch_assoc($result);
	$path  = $row[Path];
	$title = DBToField($row[Title]);
	$desc  = DBToField($row[LinkDescription]);
	$link  = $row[Link];
	$levelString = getLevelSelects($path);
	
	// See if this link exists in any other categories
	$sql = "SELECT * from transLinks WHERE Title = '$title' AND Link = '$link' AND LinkID <> '$linkID'";
	$result = mysql_db_query($dbname,$sql);
	$rows = mysql_num_rows($result);
	$i=1;
	if ($rows>0) {
		
		while ($value = mysql_fetch_assoc($result)) {
			$path  = $value[Path];
			$title = DBToField($value[Title]);
			$desc  = DBToField($value[LinkDescription]);
			$link  = $value[Link];
			$levelString .= '~~|~~'.getLevelSelects($path);
			$i++;
		}
	}
	// See if we have 3 sets of select menus in levelString
	
	if ($i<3) {
		if ($i == 1) {			
			$levelString .= '~~|~~'.getLevelSelects().'~~|~~'.getLevelSelects();
		} elseif ($i == 2) {
			$levelString .= '~~|~~'.getLevelSelects();
		}
	}
	$returnEditString = $linkID.'~~|~~'.$path.'~~|~~'.$title.'~~|~~'.$desc.'~~|~~'.$link.'~~|~~'.$levelString;
	return $returnEditString;
}

function resourceEditConfirm($phpString) {
	global $returnString, $dbname, $db, $db_selected;
	
	$stringArray = explode('|',$phpString);
	$linkID = $stringArray[0];
	$linkTitle = fieldToDB($stringArray[1]);
	$linkDesc  = fieldToDB($stringArray[2]);
	$linkURL   = fieldToDB($stringArray[3]);
	
	$sql = "UPDATE transLinks SET
			Title           = '$linkTitle',
			LinkDescription = '$linkDesc',
			Link            = '$linkURL'
			WHERE LinkID = '$linkID'";
	$result = mysql_db_query($dbname,$sql);
	
	$returnString = $phpString;
	return $returnString;
}

function addResourceCat($mainCat,$subCat,$subSubCat,$linkID) {
	global $returnString, $dbname, $db, $db_selected;
	$userid = $_SESSION[UID];	

	// Determine PathID
	$sql = "SELECT LevelID from transLevels WHERE Path = '$subSubCat'";
	$result = mysql_db_query($dbname,$sql);
	$row = mysql_fetch_assoc($result);
	$pathID = $row[LevelID];	

	$sql = "INSERT into transLinkPath (
			LinkID,
			PathID,
			MainPath,
			Userid
			) values (
			'$linkID',
			'$pathID',
			'$mainCat',
			'$userid'
			)";
	$result = mysql_db_query($dbname,$sql);	

	// Return full path name
	$returnString = buildBreadcrumbs($subSubCat).'|'.$pathID.'|'.$subSubCat.'|'.$linkID;
	return $returnString;
}

function removeResourceCat($pathID,$linkID) {
	global $returnString, $dbname, $db, $db_selected;
	$userid = $_SESSION[UID];

	$sql = "DELETE from transLinkPath WHERE LinkID = '$linkID' AND PathID = '$pathID'";
	$result = mysql_db_query($dbname,$sql);
}

function removeOrphanedCats() {
	global $returnString, $dbname, $db, $db_selected;
	$userid = $_SESSION[UID];

	$sql = "DELETE from transLinkPath WHERE Userid = '$userid' AND LinkID = '0'";
	$result = mysql_db_query($dbname,$sql);
}

function getResourceForEdit($linkID) {
	global $returnString, $dbname, $db, $db_selected;

	$returnString = '';

	$sql = "SELECT * from transLinks WHERE LinkID = '$linkID'";
	$result = mysql_db_query($dbname,$sql);
	$row = mysql_fetch_assoc($result);
	

	$lTitle = stripslashes($row[Title]);
	$lDesc  = $row[LinkDescription];
	$lURL   = $row[Link];	

	$returnString .= $lTitle.'|'.$lDesc.'|'.$lURL;	

	// Get levels for this link
	$sql = "SELECT TLP.PathID,TL.Path 
			FROM transLinkPath TLP
			LEFT JOIN transLevels TL ON TL.LevelID = TLP.PathID
			WHERE TLP.LinkID = '$linkID'";
	$result = mysql_db_query($dbname,$sql);	

	$pathString = '';
	while ($value = mysql_fetch_assoc($result)) {
		$linkPath   = $value[Path];
		$linkPathID = $value[PathID];	
		$linkPathText = buildBreadcrumbs($linkPath);

		if (!empty($linkPathText)) {	
			$pathString .= '<div id="path'.$linkPathID.'" style="height: 25px;">';
			$pathString .= '<a href="#" onClick="removeResourceCat('.$linkPathID.','.$linkID.'); return false;" title="Remove this category">';
			$pathString .= '<img src="images/iconError.gif" style="border: none;" alt="Remove this category" /></a>&nbsp;';
			$pathString .= '<a href="http://www.tcntransition.org'.$linkPath.'" target="_blank">'.buildBreadcrumbs($linkPath).'</a></div>';
		}	
	}
	$returnString .= '|'.$pathString.'|'.$linkID;
	return $returnString;
}

function createResourceTree($nodeID=null,$level=null) {
	global $breadCrumbs, $resourceString, $dbname, $db, $db_selected;
	
	if ( $level == 1 ) {
		// Get path from levelID
		$sql  = "SELECT Path from transLevels WHERE LevelID = '$nodeID'";
		$result = mysql_db_query($dbname,$sql);
		$row = mysql_fetch_assoc($result);
		$levelPath = $row[Path];
		
		// Parse path
		
		$sql2 = "SELECT * from transLevels WHERE Path LIKE '$levelPath/%' AND SubCat = '1' AND InMainMenu = '1' ORDER BY DisplayOrder";
		$result2 = mysql_db_query($dbname,$sql2);
		
		$treeJSON = '[';
		while ($value = mysql_fetch_assoc($result2)) {
			$levelID    = $value[LevelID];
			$levelName  = stripslashes($value[LevelName]);
			$levelPath  = $value[Path];		
			
			$treeJSON .= '{"text":"'.$levelName.'","id":"'.$levelID.'","level":2,"cls":"folder"},';	
		}
		// Strip last ,
		$strLen = strlen($treeJSON);
		$treeJSON = substr($treeJSON,0,($strLen-1));
		$treeJSON .= ']';
		
	} elseif ($level == 2) {
		// Get 3rd level category
		$sql  = "SELECT Path from transLevels WHERE LevelID = '$nodeID'";
		$result = mysql_db_query($dbname,$sql);
		$row = mysql_fetch_assoc($result);
		$levelPath = $row[Path];
		
		// Parse path		
		$sql2 = "SELECT * from transLevels WHERE Path LIKE '$levelPath/%' ORDER BY DisplayOrder";
		$result2 = mysql_db_query($dbname,$sql2);
		
		$treeJSON = '[';
		while ($value = mysql_fetch_assoc($result2)) {
			$levelID    = $value[LevelID];
			$levelName  = stripslashes($value[LevelName]);
			$levelPath  = $value[Path];
			
			$treeJSON .= '{"text":"'.$levelName.'","id":"'.$levelID.'","level":3,"cls":"file","leaf":"true"},';
		}
		$treeJSON .= ']';		
	} elseif ($level == 3) {
		// Don't do anything here...we're letting the JavaScript event handler 
		// treeNodeClick in common.js handle the AJAX involved in posting links to the
		// main window		
	} else {	
		// Get all main levels
		$sql = "SELECT * from transLevels WHERE MainCat = '1' AND InMainMenu = '1' ORDER BY DisplayOrder";
		$result = mysql_db_query($dbname,$sql);
		
		$a=0;
		$treeJSON = '[';
		while ($value = mysql_fetch_assoc($result)) {
			$levelID    = $value[LevelID];
			$levelName  = stripslashes($value[LevelName]);
			$levelPath  = $value[Path];
			
			$treeJSON .= '{"text":"<b>'.$levelName.'</b>","id":"'.$levelID.'","level":1,"cls":"folder"},';
			
			$a++;
		}
		// Strip last ,
		$strLen = strlen($treeJSON);
		$treeJSON = substr($treeJSON,0,($strLen-1));
		$treeJSON .= ']';
	}	

	return $treeJSON;
}

function getBadLinks() {
	global $resourceString, $dbname, $db, $db_selected;
	
	$sql = "SELECT * from transLinks WHERE ErrorLevel = 1 ORDER BY ErrorDate DESC";
	$result = mysql_db_query($dbname,$sql);
	$results = mysql_num_rows($result);
	if ($results<1) {
		$resourceString .= 'No broken links have been reported.';
	} else {
		
		$i=1;
		while ($value = mysql_fetch_assoc($result)) {
			if (($i % 2) > 0) { $class = 'noRowClass'; }
			else { $class = "altRow"; }
			$linkID     = $value[LinkID];
			$linkTitle  = stripslashes($value[Title]);
			$linkDesc   = stripslashes($value[LinkDescription]);
			$linkDate   = $value[DateCreated];
			$linkURL    = $value[Link];
			$linkStatus = $value[Status];
			$linkViews  = $value[Views];
			$linkRankTotal = $value[RankTotal];
			$linkRanks  = $value[Ranks];
			$linkErrorCode  = $value[ErrorCode];
			$linkErrorLevel = $value[ErrorLevel];  
			$addUserID      = $value[UserID];
			$errorStatus    = 1;
			$errorDate      = $value[ErrorDate];
			$errorCode      = $value[ErrorCode];
						
			// Get contributor name
			$sql2 = "SELECT FullName from transLogin WHERE UID = '$addUserID'";
			$result2 = mysql_db_query($dbname,$sql2);
			$rows = mysql_fetch_assoc($result2);
			$contributorName = $rows[FullName];
			if (empty($contributorName)) {
					$contributorName = 'Anonymous';
			}
			$contentArray = array(
									$class,
									$linkID,
									$linkTitle,
									$linkURL,
									$linkDesc,
									$linkDate,
									$linkViews,
									$contributorName,
									$linkStatus,
									$errorStatus,	
									$errorDate,
									$errorCode
								);
			$resourceString .= renderResources($contentArray);
			$i++;
		}
		
	} // End ELSE
	$newResourceString = $resourceString.'|'.$results;
	return $newResourceString;
}

if ($_GET[createTree]==1) {
	$nodeID = $_POST[node];
	$level  = $_POST[level];
	// createResourceTree is in functions.php
	$treeJSON = createResourceTree($nodeID,$level);
	echo $treeJSON;
}
?>
